import {
  BUCKETS_UPDATE,
  BUCKETS_UPDATE_START,
  SELECT_BUCKET
} from '../actions/s3bucket';

export default function s3buckets(
  state = { buckets: [], isUpdatingBuckets: false, currentBucket: '' },
  action
) {
  switch (action.type) {
    case BUCKETS_UPDATE:
      return {
        ...state,
        buckets: [...action.payload.buckets],
        isUpdatingBuckets: false
      };

    case BUCKETS_UPDATE_START:
      return {
        ...state,
        buckets: [],
        isUpdatingBuckets: true
      };
    case SELECT_BUCKET:
      return {
        ...state,
        currentBucket: action.payload.bucket
      };
    default:
      return state;
  }
}
